package com.xue.maper;

import com.xue.entity.Community;
import com.xue.entity.Dept;
import com.xue.entity.Person;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface CommunityRepository extends Neo4jRepository<Community, Long> {

    @Query("match (u:user),(c:community) where u.name=$username and c.name=$communityname create (c)-[r:contain]->(u)")
    void createRelation(@Param("username") String username,@Param("communityname") String communityname);

    @Query("match p=(c:community)-[r:contain]->(u:user) return c.name as name,count(u) as usercount")
    List<Map<String, Object>> communityOfUserCount();
}
